import { createBrowserRouter,createHashRouter } from "react-router-dom";
import Reg from "./pages/Reg";
import Login from "./pages/Login";
import Manage from './pages/Manage';
import Student from "./pages/student";
import Class from "./pages/class";
import Teacher from "./pages/teacher";
import ErrorPage from "./pages/ErrorPage";
import TestPage from "./pages/TestPage";
import { getToken } from "./services/user";
const router = createBrowserRouter([
    {
        path: "/test",
        element: <TestPage></TestPage>
    },
    {
        path: "/",
        element: <Reg></Reg>,
        errorElement: <ErrorPage></ErrorPage>
    },
    {
        path: "/reg",
        element: <Reg></Reg>,
    },
    {
        path: "/login",
        element: <Login></Login>,
    },
    {
        path: "/manage",
        element: <Manage></Manage>,
        errorElement: <ErrorPage></ErrorPage>,
        loader: async () => {
            let {data} = await getToken();
            return data;
        },
        children:[
            {
                path: "student",
                element: <Student></Student>,
            },
            {
                path: "class",
                element: <Class></Class>,
            },
            {
                path: "teacher",
                element: <Teacher></Teacher>,
            }
        ]
    },
]);

export default router;
